class Admin::Api::SecondCategoriesController < Admin::Api::BaseController


  def index
    @categories = Category.where(depth: 1).all
    items = @categories.map{|c| c.summary_builder}
    api_success(message: '', data: { items: items })
  end

  def create
    @category = Category.create(name: params[:name])
    if @category.save
      api_success(data: {category: @category.summary_builder})
    else
      api_error
    end
  end

  def update
    @category = Category.find_by(parent_id: params[:parent_id], id: params[:id])
    if @category.update(name: params[:name])
      api_success
    else
      api_error
    end
  end

end
